package com.fita.entity.dto.ehi.response;

import java.beans.Transient;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.DigestUtils;
import com.fita.entity.car.VehicleCategory;
import com.fita.entity.car.VehicleSize;
import com.fita.entity.set.SetPayType;

public class VehicleCore {
    
    private int uuid;
    
    private String categoryCode;
    
    private String sizeCode;
    
    private String doorCount;
    
    private Boolean airConditionIn;
    
    /**
     * 手动/自动
     */
    private String transmissionType;
    
    /**
     * 车型名称
     */
    private String modelName;
    
    private String modelCode;
    
    private String picture;
    
    /**
     * 乘客数量
     */
    private String passengerQuantity;
    
    /**
     * 气囊
     */
    private Integer baggageQuantity;
    
    private BigDecimal totalAmount;
    
    private BigDecimal esimatedTotalAmount;
    
    private BigDecimal totalAmount2;
    
    private BigDecimal esimatedTotalAmount2;
    
    private Long set1Id;
    
    private SetPayType set1PayType;
    
    private Long set2Id;
    
    private SetPayType set2PayType;
    
    private String currencyCode;
    
    
    private List<VehicleCoreCharge> vehicleCharges;
    
    private List<VehicleCoreFee> fees;
    
    private String referenceId;
    
    private Date referenceDate;
    
    private String referenceType;
    
    private String rateQualifier;
    
    /**
     * The default constructor
     */
    public VehicleCore() {
    }
    
    public VehicleCore(String categoryCode ,String sizeCode , String doorCount, Boolean airConditionIn ,
            String transmissionType ,String modalName ,String modalCode ,String picture ,
            String passengerQuantity , Integer baggageQuantity , BigDecimal totalAmount ,
            BigDecimal esimatedTotalAmount ,String currencyCode, String rateQualifier) {
        this.categoryCode = categoryCode;
        this.sizeCode = sizeCode;
        this.doorCount = doorCount;
        this.airConditionIn = airConditionIn;
        this.transmissionType = transmissionType;
        this.modelName = modalName;
        this.modelCode = modalCode;
        this.picture = picture;
        this.passengerQuantity = passengerQuantity;
        this.baggageQuantity = baggageQuantity;
        this.totalAmount = totalAmount;
        this.esimatedTotalAmount = esimatedTotalAmount;
        this.currencyCode = currencyCode;
        this.rateQualifier = rateQualifier;
        
    }
    
    
    
    
    /**
	 * @param categoryCode
	 * @param sizeCode
	 * @param doorCount
	 * @param airConditionIn
	 * @param transmissionType
	 * @param modelName
	 * @param modelCode
	 * @param picture
	 * @param passengerQuantity
	 * @param baggageQuantity
	 * @param totalAmount
	 * @param esimatedTotalAmount
	 * @param totalAmount2
	 * @param esimatedTotalAmount2
	 * @param currencyCode
	 * @param vehicleCharges
	 * @param fees
	 * @param rateQualifier
	 */
	public VehicleCore(String categoryCode, String sizeCode, String doorCount, Boolean airConditionIn,
			String transmissionType, String modelName, String modelCode, String picture, String passengerQuantity,
			Integer baggageQuantity, BigDecimal totalAmount, BigDecimal esimatedTotalAmount, BigDecimal totalAmount2,
			BigDecimal esimatedTotalAmount2, String currencyCode, List<VehicleCoreCharge> vehicleCharges,
			List<VehicleCoreFee> fees, String rateQualifier) {
		super();
		this.categoryCode = categoryCode;
		this.sizeCode = sizeCode;
		this.doorCount = doorCount;
		this.airConditionIn = airConditionIn;
		this.transmissionType = transmissionType;
		this.modelName = modelName;
		this.modelCode = modelCode;
		this.picture = picture;
		this.passengerQuantity = passengerQuantity;
		this.baggageQuantity = baggageQuantity;
		this.totalAmount = totalAmount;
		this.esimatedTotalAmount = esimatedTotalAmount;
		this.totalAmount2 = totalAmount2;
		this.esimatedTotalAmount2 = esimatedTotalAmount2;
		this.currencyCode = currencyCode;
		this.vehicleCharges = vehicleCharges;
		this.fees = fees;
		this.rateQualifier = rateQualifier;
	}

    /**
     * 获得该车辆的签名
     * @return
     */
	public String getVehicleSignature(){

        String sentence = sizeCode + totalAmount + modelCode + currencyCode;

        String code = DigestUtils.md5DigestAsHex(sentence.getBytes());

        return code;
    }

    public String getModelCodeClassDesc() {
        return VehicleSize.ssipOf(this.getModelCodeClass()) != null ? VehicleSize.ssipOf(this.getModelCodeClass()).getChineseName() : StringUtils.EMPTY;
    }
    
    public String getCategoryCodeDesc() {
        return VehicleCategory.codeOf(this.getCategoryCode()) != null ? VehicleCategory.codeOf(this.getCategoryCode()).getChineseName() : StringUtils.EMPTY;
    }
	
	public VehicleCore bindReference(String referenceId, Date referenceDate, String type) {
        this.referenceDate = referenceDate;
        this.referenceId = referenceId;
        this.referenceType = type;
        
        return this;
    }
	
	 public VehicleCore bindVehicleCoreCharges(List<VehicleCoreCharge> vehicleCharges) {
		 
		 	this.vehicleCharges = vehicleCharges;
		 	
	        return this;
	    }
    
    public VehicleCore bindFees(List<VehicleCoreFee> fees) {
        this.fees = fees;
        return this;
    }
    
    /**
     * 
     * @param set1Id
     * @param set2Id
     * @param totalAmount2
     * @param totalAmount
     * @return
     */
    public VehicleCore editPrice(Long set1Id, SetPayType set1PayType, Long set2Id, SetPayType set2PayType, BigDecimal totalAmount, BigDecimal totalAmount2, BigDecimal esimatedTotalAmount, BigDecimal esimatedTotalAmount2) {
        this.set1Id = set1Id;
        this.set1PayType = set1PayType;
        this.set2Id = set2Id;
        this.set2PayType = set2PayType;
        this.totalAmount = totalAmount;
        this.totalAmount2 = totalAmount2;
        this.esimatedTotalAmount = esimatedTotalAmount;
        this.esimatedTotalAmount2 = esimatedTotalAmount2;
        
        this.uuid = this.hashCode();
        
        return this;
    }
    
    /**
     * 
     * @return
     */
    public String vehicleCharge() {
        if(this.vehicleCharges == null || this.vehicleCharges.isEmpty()) {
            return "";
        }
        
        String result = "";
        for(VehicleCoreCharge vehicleCoreCharge : this.vehicleCharges) {
            if(StringUtils.equals(vehicleCoreCharge.getPurpose(), "2")) {
                result = result + "<div class='item' style='padding-left: .25rem;'>" + vehicleCoreCharge.getDescription() + "(" + vehicleCoreCharge.getCurrencyCode() + " " + vehicleCoreCharge.getAmount() + ")</div>";
            }
        }
        return result;
    }
    
    @Transient
    public String getVehicleChargeString() {
        return this.vehicleCharge();
    }
    
    /**
     * 
     * @return
     */
    
    public String vehicleChargeId() {
        if(this.vehicleCharges == null || this.vehicleCharges.isEmpty()) {
            return "";
        }
        System.out.println("current vehicleCharges:" + vehicleCharges);
        List<String> result = new ArrayList<String>();
        for(VehicleCoreCharge vehicleCoreCharge : this.vehicleCharges) {
            if(StringUtils.equals(vehicleCoreCharge.getPurpose(), "2")) {
                String message = vehicleCoreCharge.getId().toString() + "|" + vehicleCoreCharge.getCurrencyCode() + "|" + vehicleCoreCharge.getAmount().toString();
                result.add(message);
            }
        }
        return String.join(",", result);
    }
    
    @Transient
    public String getVehicleChargeIdString() {
        return this.vehicleChargeId();
    }
    
    /**
     * 
     * @return
     */
    public String feeInclude() {
        if(this.fees == null || this.fees.isEmpty()) {
            return "";
        }
        
        String result = "";
        for(VehicleCoreFee fee : this.fees) {
            if(fee.getIncludedInRate()) {
            	//result = result + "<div class='item' style='padding-left: .25rem;'>" + fee.getDescription() + "(" + fee.getCurrencyCode() + " " + fee.getAmount() + ")</div>";
            	result = result + "<div class='item' style='padding-left: .25rem;'>" + fee.getDescription().replaceAll("'", "&apos;") + "</div>";
                
            }
        }
        
        return result;
    }
    
    @Transient
    public String getFeeIncludeString() {
        return this.feeInclude();
    }
    
    /**
     * 
     * @return
     */
    public String feeUnInclude() {
        if(this.fees == null || this.fees.isEmpty()) {
            return "";
        }
        
        String result = "";
        for(VehicleCoreFee fee : this.fees) {
            if(!fee.getIncludedInRate()) {
                result = result + "<div class='item' style='padding-left: .25rem;'>" + fee.getDescription().replaceAll("'", "&apos;") + "(" + fee.getCurrencyCode() + " " + fee.getAmount() + ")</div>";
            }
        }
        
        return result;
    }
    
    @Transient
    public String getFeeUnIncludeString() {
        return this.feeUnInclude();
    }
    
    /**
     * 
     * @return
     */
    public String includeOrderFeeId() {
        if(this.fees == null || this.fees.isEmpty()) {
            return "";
        }
        System.out.println("current fees:" + fees);
        List<String> result = new ArrayList<String>();
        for(VehicleCoreFee fee : this.fees) {
            if(fee.getIncludedInRate()) {
                String message = fee.getOrderFeeId().toString() + "|" + fee.getCurrencyCode() + "|" + fee.getAmount().toString();
                result.add(message);
            }
        }
        
        return String.join(",", result);
    }
    
    @Transient
    public String getIncludeOrderFeeIdString() {
        return this.includeOrderFeeId();
    }
    
    /**
     * 
     * @return
     */
    public String unIncludeOrderFeeId() {
        if(this.fees == null || this.fees.isEmpty()) {
            return "";
        }
        
        List<String> result = new ArrayList<String>();
        for(VehicleCoreFee fee : this.fees) {
            if(!fee.getIncludedInRate()) {
                String message = fee.getOrderFeeId().toString() + "|" + fee.getCurrencyCode() + "|" + fee.getAmount().toString();
                result.add(message);
            }
        }
        
        return String.join(",", result);
    }
    
    @Transient
    public String getUnIncludeOrderFeeIdString() {
        return this.unIncludeOrderFeeId();
    }
    
    public boolean isEmptyPrice2() {
        if(this.totalAmount2 == null) {
            return true;
        } else {
            return this.totalAmount2.compareTo(BigDecimal.ZERO) < 0;
        }
    }
    
    /**
     * 
     * @return
     */
    public String getModelCodeType() {
        return StringUtils.substring(this.modelCode, 1, 2);
    }
    
    public String getModelCodeClass() {
        return StringUtils.substring(this.modelCode, 0, 1);
    }
    
    /**
     * 
     * @return the uuid
     */
    public int getUuid() {
        return uuid;
    }

    /**
     * @return the categoryCode
     */
    public String getCategoryCode() {
        return categoryCode;
    }

    /**
     * @return the sizeCode
     */
    public String getSizeCode() {
        return sizeCode;
    }

    /**
     * @return the doorCount
     */
    public String getDoorCount() {
        return doorCount;
    }

    /**
     * @return the airConditionIn
     */
    public Boolean getAirConditionIn() {
        return airConditionIn;
    }

    /**
     * @return the transmissionType
     */
    public String getTransmissionType() {
        return transmissionType;
    }

    /**
     * @return the modelName
     */
    public String getModelName() {
        return modelName;
    }

    /**
     * @return the modelCode
     */
    public String getModelCode() {
        return modelCode;
    }

    /**
     * @return the picture
     */
    public String getPicture() {
        return picture;
    }

    /**
     * @return the passengerQuantity
     */
    public String getPassengerQuantity() {
        return passengerQuantity;
    }

    /**
     * @return the baggageQuantity
     */
    public Integer getBaggageQuantity() {
        return baggageQuantity;
    }

    /**
     * @return the totalAmount
     */
    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    /**
     * @return the esimatedTotalAmount
     */
    public BigDecimal getEsimatedTotalAmount() {
        return esimatedTotalAmount;
    }

    /**
     * @return the totalAmount2
     */
    public BigDecimal getTotalAmount2() {
        return totalAmount2;
    }

    /**
     * @return the esimatedTotalAmount2
     */
    public BigDecimal getEsimatedTotalAmount2() {
        return esimatedTotalAmount2;
    }

    /**
     * @return the set1Id
     */
    public Long getSet1Id() {
        return set1Id;
    }

    /**
     * @return the set1PayType
     */
    public SetPayType getSet1PayType() {
        return set1PayType;
    }

    /**
     * @return the set2Id
     */
    public Long getSet2Id() {
        return set2Id;
    }

    /**
     * @return the set2PayType
     */
    public SetPayType getSet2PayType() {
        return set2PayType;
    }

    /**
     * @return the currencyCode
     */
    public String getCurrencyCode() {
        return currencyCode;
    }

    /**
     * @return the fees
     */
    public List<VehicleCoreFee> getFees() {
        return fees;
    }

    /**
     * @return the referenceId
     */
    public String getReferenceId() {
        return referenceId;
    }

    /**
     * @return the referenceDate
     */
    public Date getReferenceDate() {
        return referenceDate;
    }

    /**
     * @return the referenceType
     */
    public String getReferenceType() {
        return referenceType;
    }

    /**
     * @return the rateQualifier
     */
    public String getRateQualifier() {
        return rateQualifier;
    }
    
    /**
     * @param uuid the uuid to set
     */
    public void setUuid(int uuid) {
        this.uuid = uuid;
    }

    /**
     * @param categoryCode the categoryCode to set
     */
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }

    /**
     * @param sizeCode the sizeCode to set
     */
    public void setSizeCode(String sizeCode) {
        this.sizeCode = sizeCode;
    }

    /**
     * @param doorCount the doorCount to set
     */
    public void setDoorCount(String doorCount) {
        this.doorCount = doorCount;
    }

    /**
     * @param airConditionIn the airConditionIn to set
     */
    public void setAirConditionIn(Boolean airConditionIn) {
        this.airConditionIn = airConditionIn;
    }

    /**
     * @param transmissionType the transmissionType to set
     */
    public void setTransmissionType(String transmissionType) {
        this.transmissionType = transmissionType;
    }

    /**
     * @param modelName the modelName to set
     */
    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    /**
     * @param modelCode the modelCode to set
     */
    public void setModelCode(String modelCode) {
        this.modelCode = modelCode;
    }

    /**
     * @param picture the picture to set
     */
    public void setPicture(String picture) {
        this.picture = picture;
    }

    /**
     * @param passengerQuantity the passengerQuantity to set
     */
    public void setPassengerQuantity(String passengerQuantity) {
        this.passengerQuantity = passengerQuantity;
    }

    /**
     * @param baggageQuantity the baggageQuantity to set
     */
    public void setBaggageQuantity(Integer baggageQuantity) {
        this.baggageQuantity = baggageQuantity;
    }

    /**
     * @param totalAmount the totalAmount to set
     */
    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    /**
     * @param esimatedTotalAmount the esimatedTotalAmount to set
     */
    public void setEsimatedTotalAmount(BigDecimal esimatedTotalAmount) {
        this.esimatedTotalAmount = esimatedTotalAmount;
    }

    /**
     * @param totalAmount2 the totalAmount2 to set
     */
    public void setTotalAmount2(BigDecimal totalAmount2) {
        this.totalAmount2 = totalAmount2;
    }

    /**
     * @param esimatedTotalAmount2 the esimatedTotalAmount2 to set
     */
    public void setEsimatedTotalAmount2(BigDecimal esimatedTotalAmount2) {
        this.esimatedTotalAmount2 = esimatedTotalAmount2;
    }

    /**
     * @param set1Id the set1Id to set
     */
    public void setSet1Id(Long set1Id) {
        this.set1Id = set1Id;
    }

    /**
     * @param set1PayType the set1PayType to set
     */
    public void setSet1PayType(SetPayType set1PayType) {
        this.set1PayType = set1PayType;
    }

    /**
     * @param set2Id the set2Id to set
     */
    public void setSet2Id(Long set2Id) {
        this.set2Id = set2Id;
    }

    /**
     * @param set2PayType the set2PayType to set
     */
    public void setSet2PayType(SetPayType set2PayType) {
        this.set2PayType = set2PayType;
    }

    /**
     * @param currencyCode the currencyCode to set
     */
    public void setCurrencyCode(String currencyCode) {
        this.currencyCode = currencyCode;
    }

    /**
     * @param fees the fees to set
     */
    public void setFees(List<VehicleCoreFee> fees) {
        this.fees = fees;
    }

    /**
     * @param referenceId the referenceId to set
     */
    public void setReferenceId(String referenceId) {
        this.referenceId = referenceId;
    }

    /**
     * @param referenceDate the referenceDate to set
     */
    public void setReferenceDate(Date referenceDate) {
        this.referenceDate = referenceDate;
    }

    /**
     * @param referenceType the referenceType to set
     */
    public void setReferenceType(String referenceType) {
        this.referenceType = referenceType;
    }

    /**
     * @param rateQualifier the rateQualifier to set
     */
    public void setRateQualifier(String rateQualifier) {
        this.rateQualifier = rateQualifier;
    }

	/**
	 * @return the vehicleCharges
	 */
	public List<VehicleCoreCharge> getVehicleCharges() {
		return vehicleCharges;
	}

	/**
	 * @param vehicleCharges the vehicleCharges to set 
	 */
	public void setVehicleCharges(List<VehicleCoreCharge> vehicleCharges) {
		this.vehicleCharges = vehicleCharges;
	}
    
    
    
    
}
